const mysql = require("mysql");

const dbconfig = require("./database");

//创建数据库服务
const pool = mysql.createPool(dbconfig.mysql);

module.exports = {
    //以后只需要调用query方法执行sql语句
    query: (sql, callback) => {
        //建立链接
        pool.getConnection((err, connection) => {
            //执行sql语句
            connection.query(sql, (error, rows) => {
                //执行回调函数
                callback(error, rows);
                //释放程序
                connection.release();
            });
        });
    },
};
